HTML 77.2%
TypeScript 10.5%
Python 9.6%
JavaScript 2.5%
1import type { Metadata } from 'next';2import { notFound, permanentRedirect } from 'next/navigation';3import { describeModel, ModelPage, type ModelPageParams } from '@/components/entity/model-page';4import { api, ApiError, apiD1, safe } from '@/lib/api';5import { routes, SITE_NAME, SITE_URL } from '@/lib/site';6import type { ModelDetail } from '@/lib/types';78type Params = { params: Promise<{ slug: string }>; searchParams: Promise<ModelPageParams> };910/** `/models/<slug>` accepts models AND artifacts, and resolves folded variants to their canonical model (`redirected_from`). */11export async function loadModelOrArtifact(slug: string): Promise<ModelDetail> {12 try {13 return await apiD1.model(slug);14 } catch (e) {15 if (e instanceof ApiError && e.notFound) notFound();16 throw e;17 }18}1920export async function generateMetadata({ params }: Params): Promise<Metadata> {21 const { slug } = await params;22 const d = await safe(apiD1.model(slug));23 if (!d || d.entity_type === 'artifact' || d.slug !== slug) return { title: 'Model', robots: { index: false } };24 const title = `${d.name} — Parameters, Context, Benchmarks & Pricing`;25 const description = describeModel(d);26 const canonical = routes.entity(d);27 return {28 title,29 description,30 alternates: { canonical },31 openGraph: { title: `${title} | ${SITE_NAME}`, description, url: `${SITE_URL}${canonical}`, type: 'article', siteName: SITE_NAME },32 twitter: { card: 'summary_large_image', title, description },33 };34}3536export default async function ModelRoute({ params, searchParams }: Params) {37 const { slug } = await params;38 const sp = await searchParams;39 const d = await loadModelOrArtifact(slug);40 // Old URLs keep resolving: artifacts live at /artifacts/<slug>; folded evaluation variants and aliases 308 to the canonical model.41 if (d.entity_type === 'artifact') permanentRedirect(routes.artifact(d.slug));42 if (d.redirected_from || d.slug !== slug) permanentRedirect(routes.entity(d));43 if (d.entity_type !== 'model' && d.entity_type !== 'quantization') notFound();44 const related = await safe(api.entityRelated(d.slug, 10));45 return <ModelPage d={d} canonical={routes.entity(d)} related={related?.items} params={sp} />;46}47